<?php 


class Item extends xObject
 {
 
	function __construct()
	{		
		xObject::__construct(core::getWorldSQL(),"item_template",MYSQL_WORLD_DB ) ;

	}
	
	function getLocalizedName($localField)
	{
		$query ="SELECT SQL_CACHE ".$this->sql_link->real_escape_string($localField)." 
				FROM locales_item WHERE entry = '".$this->entry."'";
		
		$stmt = $this->sql_link->query($query);
		if(!$stmt->num_rows) return $this->name;
		else
		{
			$exec = $stmt->fetch_array();
			if($exec[0] == "" || $exec[0] ==NULL ) return $this->name;
			else return utf8_encode($exec[0]);
		}
	}
	
	function getImg()
	{
		
		//on vérifie si on a pas l'item en local
		$imgRealpath = "/home/killingspree/web/http_".(core::getSubDomain())."/img/icons/store/items/".$this->entry.".gif";
		//sinon on dl l'image
		if(file_exists($imgRealpath))
		{
			
			return getRelativePath()."/img/icons/store/items/".$this->entry.".gif";
		}
		else
		//sinon
		{
			
			$content = file_get_contents("http://lootup.rouks.net/bbloot.php?obj=".$this->entry);
			$url = preg_match('#src=\'(.*)\'>#',$content,$regs);
			$nurl = $regs[1];
			$img=  file_get_contents($nurl);
			$fp = fopen($imgRealpath , 'w+');
			fwrite($fp, $img);
			fclose($fp);
			return  getRelativePath()."/img/icons/store/items/".$this->entry.".gif";
		}
		
	}
 }

?>